package com.tnovoselec.android.orm;


public class DBUtil {

	private DBUtil() {
		super();
	}

	public static String sqlEscapeString(String value) {
		StringBuilder escaper = new StringBuilder();
		DBUtil.appendEscapedSQLString(escaper, value);

		return escaper.toString();
	}

	public static void appendEscapedSQLString(StringBuilder sb, String sqlString) {
		if (sqlString.indexOf('\'') != -1) {
			int length = sqlString.length();
			for (int i = 0; i < length; i++) {
				char c = sqlString.charAt(i);
				if (c == '\'') {
					sb.append('\'');
				}
				sb.append(c);
			}
		} else {
			sb.append(sqlString);
		}
	}
}
